<?php defined('KX_ROOT') || exit('Permission denied');?><!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
    <title>章节管理 - 原创专区 - <?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "sitename");?></title>
    <link rel="stylesheet" href="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/css/style.css"/>
    <link rel="shortcut icon" type="image/ico" href="/favicon.ico"/>
    <meta name="author" content="www.ptcms.com">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width"/>
    <meta name="applicable-device" content="pc">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta http-equiv="Cache-Control" content="no-transform"/>
    <link rel="canonical" href="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "pcurl");?><?php echo $_SERVER['REQUEST_URI'];?>"/>
    <style>
        .labels {
            height: 51px;
        }

        .labels li {
            padding: 15px 40px;
            background-color: #e5e5e5;
            color: #929297;
            display: inline-block;
            float: left;
        }

        .labels li:hover,
        .labels li.active {
            background-color: #fff;
            color: #323237;
        }

        .container {
            padding: 20px;
        }

        .container .head {
            width: 100%;
            height: 50px;
        }

        .container .head button {
            padding: 5px 20px;
            background-color: #fff;
            border: 1px solid #C9C9C9;
            margin: 0 5px;
            border-radius: 2px;
            cursor: pointer;
        }

        .container .head button:hover {
            border-color: #f55;
            color: #f55;
        }

        .container .content .warning {
            background-color: #F7F8F8;
            border-top: 2px solid #f0f1f1;
        }

        .container .content textarea {
            color: #323237;
        }

        .container .content textarea[name=postscript] {
            border-top: 1px solid #f3f3f3 !important;
        }

        /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
        .container .content textarea::-webkit-scrollbar {
            width: 8px;
            height: 16px;
            background-color: #f5f4f5;
        }

        /*定义滑块 内阴影+圆角*/
        .container .content textarea::-webkit-scrollbar-thumb {
            background-color: #929297;
        }
    </style>
</head>
<body>
<div class="header">
    <div>
        <a href="/">
            <div class="logo"><span>原创专区</span></div>
        </a>
    </div>
</div>
<div class="body">
    <div class="left bg-white">
    <style>
        .icon {
            width: 20px;
            height: 20px;
            display: inline-block;
            vertical-align: middle;
            margin-right: 10px;
        }

        .icon-home {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-home.png");
        }

        li.active .icon-home {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-home-active.png");
        }

        .icon-novel {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-novel.png");
        }

        li.active .icon-novel {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-novel-active.png");
        }

        .icon-stat {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-stat.png");
        }

        li.active .icon-stat {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-stat-active.png");
        }

        .icon-money {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-money.png");
        }

        li.active .icon-money {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-money-active.png");
        }

        .icon-userinfo {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-userinfo.png");
        }

        li.active .icon-userinfo {
            background: url("<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-userinfo-active.png");
        }
        .add_novel:before{
            content: '+';
            width: 20px;
            height: 20px;
            display: inline-block;
            left: 60px;
            position: relative;
            margin-left: -20px;
            font-weight: 700;
        }
        .add_novel a{
            color: #929292 !important;
        }
    </style>
    <ul class="nav">
        <li class="<?php echo $pagesign == 'home'?'active':'';?>">
            <a href="<?php echo \Kuxin\Helper\Url::build("author.author.index",[],"");?>">
                <i class="icon icon-home"></i>专区首页
            </a>
        </li>
        <li class="<?php echo in_array($pagesign, ['novel','chapter'])?'active':'';?>">
            <?php if(in_array($pagesign, ['novel','chapter'])):?>
            <a href="javascript:void(0);">
                <i class="icon icon-novel"></i>作品管理
            </a>
            <ul class="sub-nav">
                <?php if(is_array($novels)): foreach($novels as $key =>$loop):?>
                <li class="<?php echo $_GET['novelid']==$loop['id']?'active':'';?>" style="width: 165px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                    <a href="<?php echo \Kuxin\Helper\Url::build("author.chapter.index",['novelid'=>$loop['id']],"");?>" title="<?php echo $loop['name'];?>"><?php echo $loop['name'];?></a>
                </li>
                <?php endforeach; endif;?>
                <li class="add_novel"><a href="<?php echo \Kuxin\Helper\Url::build("author.novel.add",[],"");?>">创建作品</a></li>
            </ul>
            <?php else:?>
            <a href="<?php echo \Kuxin\Helper\Url::build("author.novel.index",[],"");?>">
                <i class="icon icon-novel"></i>作品管理
            </a>
            <?php endif;?>
        </li>
        <li class="<?php echo $pagesign == 'stat'?'active':'';?>">
            <a href="<?php echo \Kuxin\Helper\Url::build("author.stat.index",[],"");?>">
                <i class="icon icon-stat"></i>数据统计
            </a>
        </li>
        <li class="<?php echo in_array($pagesign, ['incomeindex','incomerecord','incomemanage','incomeguarantee'])?'active':'';?>">
            <?php if(in_array($pagesign, ['incomeindex','incomerecord','incomemanage','incomeguarantee'])):?>
            <a href="javascript:void(0);">
                <i class="icon icon-money"></i>稿酬收入
            </a>
            <ul class="sub-nav">
                <li class="<?php echo $pagesign=='incomerecord'?'active':'';?>"><a href="<?php echo \Kuxin\Helper\Url::build("author.income.record",[],"");?>">收入明细</a></li>
                <li class="<?php echo in_array($pagesign, ['incomemanage','incomeguarantee'])?'active':'';?>"><a href="<?php echo \Kuxin\Helper\Url::build("author.income.manage",[],"");?>">提现管理</a></li>
            </ul>
            <?php else:?>
            <a href="<?php echo \Kuxin\Helper\Url::build("author.income.record",[],"");?>">
                <i class="icon icon-money"></i>稿酬收入
            </a>
            <?php endif;?>
        </li>
        <li class="<?php echo $pagesign == 'authorinfo'?'active':'';?>">
            <a href="<?php echo \Kuxin\Helper\Url::build("author.author.info",[],"");?>">
                <i class="icon icon-userinfo"></i>作家资料
            </a>
        </li>
    </ul>
</div>
    <div class="right">
        <div class="labels">
            <ul>
                <a href="<?php echo \Kuxin\Helper\Url::build("author.chapter.index",['novelid'=>$_GET['novelid'],'type'=>'draft'],"");?>"><li class="<?php echo $type=='draft'?'active':'';?>">草稿箱</li></a>
                <a href="<?php echo \Kuxin\Helper\Url::build("author.chapter.index",['novelid'=>$_GET['novelid'],'type'=>'published'],"");?>"><li class="<?php echo $type=='published'?'active':'';?>">已发布</li></a>
                <a href="<?php echo \Kuxin\Helper\Url::build("author.chapter.index",['novelid'=>$_GET['novelid'],'type'=>'recycle'],"");?>"><li class="<?php echo $type=='recycle'?'active':'';?>">回收站</li></a>
                <a href="<?php echo \Kuxin\Helper\Url::build("author.novel.index",['novelid'=>$_GET['novelid']],"");?>"><li>作品设置</li></a>
            </ul>
            <a href="<?php echo \Kuxin\Helper\Url::build("author.chapter.add",['novelid'=>$_GET['novelid']],"");?>" class="fr color1 bg-red plr20 ptb10">
                <img class="pr10 vertical-middle" style="height: 16px;width:16px;"
                     src="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-edit.png" alt="新建章节">新建章节
            </a>
        </div>
        <div class="container bg-white">
            <form method="post">
                <div class="head">
                    <a href="javascript:history.back();" class="fl ptb5 plr20 border-radius2 mlr5"
                       style="background-color:#f5f4f5;border 1px solid #f5f4f5">
                        <img class="mr10 vertical-middle"
                             src="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/images/icon-return.png"
                             style="width: 8px;height: 16px;" alt="返回">返回
                    </a>
                    <div class="fl ml30 pt5">
                        <label for="chapter_type" class="ptb5 color0 vertical-middle">类型</label>
                        <?php if(in_array($novel['type'],[\App\Model\Novel\Novel::TYPE_TOLL,\App\Model\Novel\Novel::TYPE_VIP_FREE])):?>
                        <input type="hidden" name="chapter_type" value="<?php echo \App\Model\Novel\Chapter::TYPE_TOLL;?>">
                        <span class="ptb5 color0 vertical-middle">收费章节</span>
                        <?php else:?>
                        <input type="hidden" name="chapter_type" value="<?php echo \App\Model\Novel\Chapter::TYPE_FREE;?>">
                        <span class="ptb5 color0 vertical-middle">公众章节</span>
                        <?php endif;?>
                    </div>
                    <span style="line-height: 30px;margin-left: 10px;" id="auto_save_tips"></span>
                    <button type="submit" class="fr color2 border-red" name="status" value="publish">发布</button>
                    <button type="submit" class="fr" name="status" value="draft">保存草稿</button>
                    <?php if($_GET['type'] != 'published'):?>
                    <button type="button" class="fr">删除</button>
                    <?php endif;?>
                </div>
                <div class="content">
                    <p class="plr15 ptb5 warning">警告：根据国家相关法律规定要求，禁止上传任何色情、低俗、涉政等违法违规内容。一旦出现我们将根据法规进行审核处理。</p>
                    <div class="mtb15">
                        <label class="color0 size24 bold">章节名称：</label>
                        <input class="border-none size24 bold color0" style="width: 700px;" type="text" name="name"
                               placeholder="请输入" value="<?php echo $chapter['name'];?>">
                        <span class="fr mt20">字数 <span class="input-number-tip"><?php echo \Kuxin\Helper\Json::decode($chapter['note'])['words'];?></span></span>
                    </div>
                    <textarea name="content" class="w100 plr10 ptb10 border-none" style="width:930px;height:405px;"
                              placeholder="章节内容"><?php echo $chapter['content'];?></textarea>
                    <textarea name="postscript" class="w100 plr10 ptb10 border-none" style="width:930px;height:50px"
                              placeholder="作者想说的话"><?php echo $chapter['postscript'];?></textarea>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="footer text-center">
    <?php $list=\Kuxin\Block::show('page.list', []);?>
    <span class="aboutlink">
        <?php if(is_array($list)): foreach($list as $key =>$loop):?>
        <a href="<?php echo \Kuxin\Helper\Url::build("page.detail",['pageid'=>$loop['id'],'key'=>$loop['key']],"");?>" title="<?php echo $loop['name'];?>"> <?php echo $loop['name'];?> </a>
        <?php endforeach; endif;?>
    </span>
    <span class="inline-block ml40">Copyright © 2009 - 2019 <a href="<?php echo $pt['config']['siteurl'];?>" target="_blank"><?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "sitename");?></a>. All Rights Reserved . 版权所有<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "sitename");?></span>
</div>
<script src="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/js/jquery-3.3.1.js"></script>
<script src="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/js/layer/layer.js"></script>
<script src="<?php echo \Kuxin\Helper\Arr::getValue($_kxcms_config, "resurl");?>/template/kxwebno1/author/js/common.js"></script>
<script>
    var isSave = true;
    $("textarea").on('keydown', function (e) {
        if (e.keyCode === 9) {
            e.preventDefault();
            var indent = '    ';
            var start = this.selectionStart;
            var end = this.selectionEnd;
            var selected = window.getSelection().toString();
            selected = indent + selected.replace(/\n/g, '\n' + indent);
            this.value = this.value.substring(0, start) + selected + this.value.substring(end);
            this.setSelectionRange(start + indent.length, start + selected.length);
        }
    });
    $("textarea[name=content]").on('keyup', function () {
        var str = $(this).val();
        var len = str.length;
        var reLen = 0;
        for (var i = 0; i < len; i++) {
            if (str.charCodeAt(i) < 33) {
                continue;
            }
            if (str.charCodeAt(i) >= 0 || str.charCodeAt(i) <= 128) {
                reLen += 1;
            } else {
                reLen += 2;
            }
        }
        $(".input-number-tip").html(reLen);
    });
    $("form").submit(function () {
        $('button[type=submit]').click(function(){return false});
    });

    var save_key = 'author_<?php echo $_GET['novelid'];?>_<?php echo $type;?>_<?php echo $chapter['id']?:0;?>';
    function load() {
        var data = window.localStorage.getItem(save_key);
        if (data && (data = JSON.parse(data))){
            if(confirm('上次的编辑在 '+data.saveTime+' 有未正确的保存,是否恢复?')){
                $('input[name=chapter_type]').val(data.type);
                $('input[name=name]').val(data.name);
                $('textarea[name=content]').val(data.content);
                $('textarea[name=postscript]').val(data.postscript);
            }else{
                remove();
            }
        }
    }
    $('input[name=name],textarea[name=content],textarea[name=postscript]').keyup(function () {
        isSave = false;
    });
    load();
    function save() {
        if(!isSave && ($('textarea[name=content]').val() || $('textarea[name=postscript]').val())){
            var saveTime = (new Date()).toLocaleString();
            window.localStorage.setItem(save_key, JSON.stringify({
                type: $('input[name=chapter_type]').val(),
                name: $('input[name=name]').val(),
                content: $('textarea[name=content]').val(),
                postscript: $('textarea[name=postscript]').val(),
                saveTime: saveTime
            }));
            $('#auto_save_tips').text('自动保存于:'+saveTime);
            isSave = true;
        }
    }
    function remove() {
        window.localStorage.removeItem(save_key)
    }

    setInterval(function () {save();},10000);

    $('form').submit(function () {
        remove(save_key);
        return true;
    });
</script>
</body>
</html>